using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CardDetailPanel : MonoBehaviour
{
    [SerializeField] private CardUI cradPrefab;
    [SerializeField] private GameObject cradDetailUI;
    [SerializeField] private Transform cradGroup;
    [SerializeField] private Button closeButton;
    [SerializeField] private Button drawButton;
    [SerializeField] private Button discardButton;

    private void OnEnable()
    {
        closeButton.onClick.AddListener(Hide);
        drawButton.onClick.AddListener(DrawPileShow);
        discardButton.onClick.AddListener(DiscardPileShow);
    }

    public void Show()
    {
        cradDetailUI.SetActive(true);
        DrawPileShow();
    }
    public void Hide()
    {
        cradDetailUI.SetActive(false);
    }
    public void DrawPileShow()
    {
        ShowCrad(CardSystem.instance.drawPile);
    }
    public void DiscardPileShow()
    {
        ShowCrad(CardSystem.instance.discardPile);
    }
    public void ShowCrad(List<Card> cards)
    {
        cradGroup.ClearChildren();
        foreach (Card card in cards)
        {
            var clone=Instantiate(cradPrefab, cradGroup);
            clone.gameObject.GetComponent<CardUI>().SetUp(card);
        }
    }
}
